<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Java | C·辰</title><meta name="author" content="辰"><meta name="copyright" content="辰"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Java基础# 描述">
<meta property="og:type" content="article">
<meta property="og:title" content="Java">
<meta property="og:url" content="http://example.com/2021/01/01/Java%E5%9F%BA%E7%A1%80/index.html">
<meta property="og:site_name" content="C·辰">
<meta property="og:description" content="Java基础# 描述">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/Java.png">
<meta property="article:published_time" content="2021-01-01T14:22:22.000Z">
<meta property="article:modified_time" content="2023-07-06T08:40:49.874Z">
<meta property="article:author" content="辰">
<meta property="article:tag" content="Java--基础">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/Java.png"><link rel="shortcut icon" href="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/Bell.ico"><link rel="canonical" href="http://example.com/2021/01/01/Java%E5%9F%BA%E7%A1%80/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Java',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-07-06 16:40:49'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/img/loading.gif" data-original="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog%2Fimages%2Favatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">32</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">28</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> Demo</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/c2c_shop/"><i class="fa-fw fa fa-comments-o"></i><span> 商城</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/Java.png')"><nav id="nav"><span id="blog-info"><a href="/" title="C·辰"><span class="site-name">C·辰</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> Demo</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/c2c_shop/"><i class="fa-fw fa fa-comments-o"></i><span> 商城</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Java</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-01-01T14:22:22.000Z" title="发表于 2021-01-01 22:22:22">2021-01-01</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-07-06T08:40:49.874Z" title="更新于 2023-07-06 16:40:49">2023-07-06</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Java/">Java</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.3k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>9分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Java"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Java"><a href="#Java" class="headerlink" title="Java"></a>Java</h1><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//先赋值在a再加</span></span><br><span class="line"><span class="type">int</span> b=a++</span><br><span class="line"> </span><br><span class="line"><span class="comment">//先加再赋值</span></span><br><span class="line"><span class="type">int</span> c=++a</span><br><span class="line">    </span><br><span class="line"><span class="comment">//动态数组 ArrayList</span></span><br><span class="line">List&lt;Phone&gt; list=<span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;Phone&gt;();</span><br></pre></td></tr></table></figure>

<p><br/>		<br/></p>
<hr>
<h2 id="位运算"><a href="#位运算" class="headerlink" title="位运算"></a>位运算</h2><p>A &#x3D; 0011 1100</p>
<p>B &#x3D; 0000 1101</p>
<p>A&amp;B(同1)：0000 1100</p>
<p>A|B(1则1)：0011 1101</p>
<p>~B:1111 0010</p>
<p>位计算：</p>
<p>&lt;&lt;	*2</p>
<p>&#x2F;&#x2F;   &gt;&gt;  &#x2F;2 </p>
<p><br/>		<br/></p>
<hr>
<h2 id="Scanner"><a href="#Scanner" class="headerlink" title="Scanner"></a>Scanner</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">Scanner</span> <span class="variable">scanner</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line"><span class="comment">//判断是否还有输入</span></span><br><span class="line"><span class="keyword">if</span>(scanner.hasNextLine)&#123;String s=in.nextLine()&#125;</span><br><span class="line"><span class="comment">//next()空格结束</span></span><br><span class="line"><span class="comment">//nextLine()回车结束</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//scanner.hasNextInt 判断下次输入是否为整数</span></span><br><span class="line"><span class="comment">//scanner.hasNextFloat 判断下次输入是否为小数</span></span><br></pre></td></tr></table></figure>

<p><br/>		<br/></p>
<hr>
<h2 id="Switch"><a href="#Switch" class="headerlink" title="Switch"></a>Switch</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line">Switch(data)&#123;</span><br><span class="line">	<span class="keyword">case</span> <span class="title function_">value</span><span class="params">(value==data)</span>:</span><br><span class="line">		<span class="keyword">break</span><span class="string">&#x27;</span></span><br><span class="line"><span class="string">	default:System.out.print(&quot;No&quot;)</span></span><br><span class="line"><span class="string">&#125;</span></span><br></pre></td></tr></table></figure>

<p><br/>		<br/></p>
<hr>
<h2 id="While"><a href="#While" class="headerlink" title="While"></a>While</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line">white(<span class="literal">true</span>)&#123;</span><br><span class="line">    <span class="comment">//内容</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p><br/>		<br/></p>
<hr>
<h2 id="do-while"><a href="#do-while" class="headerlink" title="do..while"></a>do..while</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//先执行后判断</span></span><br><span class="line"><span class="keyword">do</span>&#123;</span><br><span class="line"><span class="comment">//代码</span></span><br><span class="line">&#125;<span class="keyword">while</span>(<span class="literal">true</span>)</span><br></pre></td></tr></table></figure>



<p><br/>		<br/></p>
<hr>
<h2 id="结束循环"><a href="#结束循环" class="headerlink" title="结束循环"></a>结束循环</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//跳出循环</span></span><br><span class="line"><span class="keyword">break</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//结束单轮循环 --跳出外层循环 （外层）outer：    continue：outer</span></span><br><span class="line"><span class="keyword">continue</span>;</span><br></pre></td></tr></table></figure>



<p><br/>		<br/></p>
<hr>
<h2 id="可变参数"><a href="#可变参数" class="headerlink" title="可变参数"></a>可变参数</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line">test(<span class="number">1</span>,<span class="number">2</span>)</span><br><span class="line"></span><br><span class="line">    <span class="comment">//形参a 要放最后</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test</span><span class="params">(<span class="type">int</span>... a)</span>&#123;</span><br><span class="line">    <span class="comment">//a收到为数组 </span></span><br><span class="line">    System.out.print(a[<span class="number">0</span>],a[<span class="number">1</span>])</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p><br/>		<br/></p>
<hr>
<h2 id="数组-–-Arrays"><a href="#数组-–-Arrays" class="headerlink" title="数组 – Arrays"></a>数组 – Arrays</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">int</span>[] a=<span class="keyword">new</span> <span class="title class_">int</span>[<span class="number">9</span>];</span><br><span class="line"><span class="type">int</span>[] b=&#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>&#125;</span><br><span class="line">String b[]=<span class="keyword">new</span> <span class="title class_">String</span>[<span class="number">9</span>];</span><br><span class="line"></span><br><span class="line"><span class="comment">//数组可封装为参数</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">printc</span><span class="params">(<span class="type">int</span>[] arrayc)</span>&#123;</span><br><span class="line">    System.out.print(arrayc[<span class="number">0</span>])</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="type">int</span>[] reverse(<span class="type">int</span>[] arrays)&#123;</span><br><span class="line">    <span class="type">int</span>[] c=arrays;</span><br><span class="line">    <span class="keyword">return</span> c</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//Arrays</span></span><br><span class="line">	<span class="comment">//数组赋值--覆盖</span></span><br><span class="line">	Arrays.fill(b,<span class="number">0</span>)<span class="comment">//全部替换填充0</span></span><br><span class="line">     Arrays.fill(b,<span class="number">1</span>,<span class="number">3</span>,<span class="number">0</span>)<span class="comment">//1~3之间</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">//输出数组 </span></span><br><span class="line">	Arrays.toString(c)</span><br><span class="line">     </span><br><span class="line">    <span class="comment">//排序</span></span><br><span class="line">     Arrays.sort(c)</span><br><span class="line">        </span><br><span class="line">    <span class="comment">//比较</span></span><br><span class="line">     Arrays.equals</span><br><span class="line">     </span><br></pre></td></tr></table></figure>



<p><br/>		<br/></p>
<hr>
<h2 id="多维数组"><a href="#多维数组" class="headerlink" title="多维数组"></a>多维数组</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">int</span> a[][]=<span class="keyword">new</span> <span class="title class_">int</span>[<span class="number">2</span>][<span class="number">2</span>];</span><br><span class="line"><span class="type">int</span>[][] b=&#123;&#123;<span class="number">1</span>,<span class="number">2</span>&#125;,&#123;<span class="number">2</span>,<span class="number">3</span>&#125;,&#123;<span class="number">3</span>,<span class="number">4</span>&#125;,&#123;<span class="number">4</span>,<span class="number">5</span>&#125;,&#123;<span class="number">5</span>,<span class="number">6</span>&#125;&#125;</span><br><span class="line"><span class="comment">//四行两列</span></span><br><span class="line"><span class="comment">//1 2</span></span><br><span class="line"><span class="comment">//2 3</span></span><br><span class="line"><span class="comment">//3 4</span></span><br><span class="line"><span class="comment">//4 5</span></span><br><span class="line"><span class="comment">//5 6</span></span><br></pre></td></tr></table></figure>





<p><br/>		<br/></p>
<hr>
<h2 id="增强循环"><a href="#增强循环" class="headerlink" title="增强循环"></a>增强循环</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//for-Each 无下标</span></span><br><span class="line"><span class="type">int</span>[] c= &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>&#125;;</span><br><span class="line">        <span class="keyword">for</span> (array:c)&#123;</span><br><span class="line">            System.out.println(array);</span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure>





<p><br/>		<br/></p>
<hr>
<h2 id="面向对象"><a href="#面向对象" class="headerlink" title="面向对象"></a>面向对象</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//Student</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Student</span> &#123;</span><br><span class="line">      <span class="comment">//静态 -- 表示为一个类</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">saya</span><span class="params">()</span>&#123;</span><br><span class="line">        System.out.say(<span class="string">&quot;1&quot;</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//非静态 可直接调用静态</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">sayb</span><span class="params">()</span>&#123;</span><br><span class="line">        saya();</span><br><span class="line">        System.out.sayc(<span class="string">&quot;1&quot;</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//Demo</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Demo</span> &#123;</span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="comment">//静态直接调用</span></span><br><span class="line">        Student.saya();</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//调用非静态需要 实例 化</span></span><br><span class="line">        Student student=<span class="keyword">new</span> <span class="title class_">Student</span>();</span><br><span class="line">        student.sayb();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><br/>		<br/></p>
<hr>
<h2 id="封装"><a href="#封装" class="headerlink" title="封装"></a>封装</h2><p>1.私有（private）get&#x2F;set</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">Student student=<span class="keyword">new</span> <span class="title class_">Stuent</span>();</span><br><span class="line">student.setName(<span class="string">&quot;chen&quot;</span>);</span><br><span class="line">System.out.print(student.getName())</span><br></pre></td></tr></table></figure>

<p><br/>		<br/></p>
<hr>
<h2 id="修饰符"><a href="#修饰符" class="headerlink" title="修饰符"></a>修饰符</h2><ol>
<li>&#x2F; public</li>
<li>&#x2F; protected</li>
<li>&#x2F; default  默认</li>
<li>&#x2F; private</li>
</ol>
<p><br/>		<br/></p>
<hr>
<h2 id="继承-–-extends"><a href="#继承-–-extends" class="headerlink" title="继承 – extends"></a>继承 – extends</h2><p>​	&#x2F;&#x2F;单继承</p>
<p>​	&#x2F;&#x2F;子类继承了父类，就会拥有父类的全部方法（共有），不需要定义，直接实例化子列进行方法的调用</p>
<br/>	

<p>1.Object类</p>
<p>​	&#x2F;&#x2F;所有类默认继承Object类</p>
<br/>

<p>2.Super</p>
<blockquote>
<p>super注意点：<br>        1.super调用父类的构造方法，必须在构造方法的第一个<br>        2.super必须只能出现在子类的方法或者构造方法中！<br>        3.super和this不能同时调用构造方法！<br>Vs this<br>    代表的对象不同：<br>        this:本身调用者这个对象<br>        super:代表父类对象的应用<br>    前提<br>        this：没哟继承也可以使用<br>        super:只能在继承条件才可以使用<br>    构造方法<br>        this();本类的构造<br>        super():父类的构造！</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//this 指向当前类</span></span><br><span class="line"><span class="comment">//super 指向父类</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">this</span>.name;		<span class="built_in">this</span>.printc();</span><br><span class="line"><span class="built_in">super</span>.name;		<span class="built_in">super</span>.printc();</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//super(); 和无参构造方法一样被隐藏</span></span><br><span class="line"><span class="built_in">super</span>();<span class="comment">//调用父类无参构造方法</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<br/>

<p>3.重写</p>
<p>重写：需要有继承关系，子类重写父类的方法！<br>    1.方法名必须相同<br>    2.参数列表列表必须相同<br>    3.修饰符：范围可以扩大但不能缩小：public&gt;Protected&gt;Default&gt;private<br>    4.抛出的异常：范围，可以被缩小，但不能扩大；ClassNotFoundException–&gt;Exception(大)<br>重写，子类的方法和父类必要一致；方法体不同！</p>
<br/>	

<p>①当父类和子类方法都是静态方法时，方法的调用只和左边定义的数据类型有关</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//父类</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">B</span>&#123;</span><br><span class="line">	<span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">test</span><span class="params">()</span>&#123;</span><br><span class="line">		System.out.print(<span class="string">&quot;B&quot;</span>)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//子类</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">A</span> extend B&#123;</span><br><span class="line">	<span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">test</span><span class="params">()</span>&#123;</span><br><span class="line">		System.out.print(<span class="string">&quot;A&quot;</span>)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//test</span></span><br><span class="line">A a=<span class="keyword">new</span> <span class="title class_">A</span>();</span><br><span class="line">a.test(); <span class="comment">//--&gt;输出 A；</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//父类的引用指向子类</span></span><br><span class="line"><span class="type">B</span> <span class="variable">b</span> <span class="operator">=</span><span class="keyword">new</span> <span class="title class_">A</span>();</span><br><span class="line">b.test();  <span class="comment">// --&gt; 输出B；</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//b是a new出来的对象，因此调用a的方法</span></span><br><span class="line"><span class="comment">//静态方法是类的方法，非静态方法是对象的方法</span></span><br><span class="line"><span class="comment">//静态时，调用b类的方法,b是用b类定义的</span></span><br><span class="line"><span class="comment">//非静态时，b调用对象的方法，b是a类new出来的对象</span></span><br></pre></td></tr></table></figure>

<br/>	

<p>①当父类和子类方法都是非静态 –&gt;重写 父类的方法</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//父类</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">B</span>&#123;</span><br><span class="line">	<span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">test</span><span class="params">()</span>&#123;</span><br><span class="line">		System.out.print(<span class="string">&quot;B&quot;</span>)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//子类</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">A</span> extend B&#123;</span><br><span class="line">    <span class="meta">@Override</span> <span class="comment">//重写</span></span><br><span class="line">	<span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">test</span><span class="params">()</span>&#123;</span><br><span class="line">		System.out.print(<span class="string">&quot;A&quot;</span>)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//test</span></span><br><span class="line">A a=<span class="keyword">new</span> <span class="title class_">A</span>();</span><br><span class="line">a.test(); <span class="comment">//--&gt;输出 A；</span></span><br><span class="line"></span><br><span class="line"><span class="type">B</span> <span class="variable">b</span> <span class="operator">=</span><span class="keyword">new</span> <span class="title class_">A</span>();</span><br><span class="line">b.test();  <span class="comment">// --&gt; 输出A；</span></span><br></pre></td></tr></table></figure>



<p><br/>		<br/></p>
<hr>
<h2 id="多态"><a href="#多态" class="headerlink" title="多态"></a>多态</h2><p>多态注意事顶：<br>    1.多态是方法的多态，属性没有多态<br>    2.父类和子类，有联系类型转换异常！CLassCastException&#x2F;<br>    3。存在条件：继承关系，方法需要重写，父类引用指向子类对象！（Father f1 new Son();）</p>
<p><br/>		<br/></p>
<hr>
<h2 id="Static"><a href="#Static" class="headerlink" title="Static"></a>Static</h2><p>&#x2F;&#x2F;static属于类，非static属于对象</p>
<p>&#x2F;&#x2F;静态 – 类名直接调用</p>
<p><br/>		<br/></p>
<hr>
<h2 id="代码块"><a href="#代码块" class="headerlink" title="代码块"></a>代码块</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//匿名代码块 --跟随对象产生 -- 使用：可赋初始值</span></span><br><span class="line">&#123;</span><br><span class="line">    System.out.print(<span class="string">&quot;匿名代码块&quot;</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//static -- 跟随类产生 -- 只执行一次</span></span><br><span class="line">&#123;</span><br><span class="line">    System.out.print(<span class="string">&quot;静态代码块&quot;</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><br/>		<br/></p>
<hr>
<h2 id="抽象类-abstract"><a href="#抽象类-abstract" class="headerlink" title="抽象类 - abstract"></a>抽象类 - abstract</h2><p>&#x2F;&#x2F;1.不能new 这个抽象类，只能靠子类去实现，约束！</p>
<p>&#x2F;&#x2F;2.抽象类中可以写普通方法</p>
<p>&#x2F;&#x2F;3.抽象方法必须在抽象类zh</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">class</span> <span class="title class_">chouxianglei</span>&#123;</span><br><span class="line">    <span class="comment">//抽象方法，只有方法名字，没有方法的实现</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> <span class="title function_">print</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><br/>		<br/></p>
<hr>
<h2 id="接口-–-interface"><a href="#接口-–-interface" class="headerlink" title="接口 – interface"></a>接口 – interface</h2><p>可以多继承多接口</p>
<p>作用：<br>    1,约束<br>    2,定义一些方法，让不同的人实现<del>10–&gt;1<br>    3.public abstract		&#x2F;&#x2F;void save();<br>    4.public static final 	 &#x2F;&#x2F;int age&#x3D;18;<br>    5,接口不能被实例化</del>，接口中没有构造方法~<br>    6.implements可以实现多个接口<br>    7,必须要重写接口中的方法~</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//接口中的所有的定义都是抽象的  public abstract</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> <span class="title function_">save</span><span class="params">()</span>;</span><br><span class="line"><span class="keyword">void</span> <span class="title function_">save</span><span class="params">()</span>;</span><br><span class="line"><span class="type">int</span> age=<span class="number">18</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//实现类 Impl -- implement -- 要求重写接口中的方法</span></span><br></pre></td></tr></table></figure>



<p><br/>		<br/></p>
<hr>
<h2 id="类"><a href="#类" class="headerlink" title="类"></a>类</h2><h3 id="内部类"><a href="#内部类" class="headerlink" title="内部类"></a>内部类</h3><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//同一个java文件可以多个class类，一个java文件只能有一个public class</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestLambdal</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="type">ILike</span> <span class="variable">iLike</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Like</span>();</span><br><span class="line">        <span class="comment">//定义类实现接口</span></span><br><span class="line">        iLike.lambda();</span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//1.定义一个函数式接口</span></span><br><span class="line"><span class="keyword">interface</span> <span class="title class_">ILike</span>&#123;</span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">lambda</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//2.实现类</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Like</span> <span class="keyword">implements</span>  <span class="title class_">ILike</span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">lambda</span><span class="params">()</span> &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;I Like Lambda&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h4 id="静态内部类"><a href="#静态内部类" class="headerlink" title="静态内部类"></a>静态内部类</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestLambdal</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//静态内部类</span></span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">Like2</span> <span class="keyword">implements</span>  <span class="title class_">ILike</span>&#123;</span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">lambda</span><span class="params">()</span> &#123;</span><br><span class="line">            System.out.println(<span class="string">&quot;I Like Lambda2&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="type">ILike</span> <span class="variable">iLike</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Like2</span>();</span><br><span class="line">        iLike.lambda();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//定义一个函数式接口</span></span><br><span class="line"><span class="keyword">interface</span> <span class="title class_">ILike</span>&#123;</span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">lambda</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="局部内部类"><a href="#局部内部类" class="headerlink" title="局部内部类"></a>局部内部类</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestLambdal</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">         </span><br><span class="line">         <span class="comment">//局部内部类--main</span></span><br><span class="line">         <span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">Like3</span> <span class="keyword">implements</span>  <span class="title class_">ILike</span>&#123;</span><br><span class="line">             <span class="meta">@Override</span></span><br><span class="line">             <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">lambda</span><span class="params">()</span> &#123;</span><br><span class="line">                 System.out.println(<span class="string">&quot;I Like Lambda3&quot;</span>);</span><br><span class="line">             &#125;</span><br><span class="line">         &#125;</span><br><span class="line">         </span><br><span class="line">        <span class="type">ILike</span> <span class="variable">iLike</span> <span class="operator">=</span> = <span class="keyword">new</span> <span class="title class_">Like3</span>();</span><br><span class="line">        iLike.lambda();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">interface</span> <span class="title class_">ILike</span>&#123;</span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">lambda</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="匿名内部类"><a href="#匿名内部类" class="headerlink" title="匿名内部类"></a>匿名内部类</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestLambdal</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//5.匿名内部类，没有类的名称，必须借助接口或者父类,没有名字初始化类 --不用将实例保存到变量中</span></span><br><span class="line">       ILike iLike=<span class="keyword">new</span> <span class="title class_">ILike</span>() &#123;</span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">lambda</span><span class="params">()</span> &#123;</span><br><span class="line">                System.out.println(<span class="string">&quot;I Like Lambda4&quot;</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line">        iLike.lambda();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">interface</span> <span class="title class_">ILike</span>&#123;</span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">lambda</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="Lambda表达式"><a href="#Lambda表达式" class="headerlink" title="Lambda表达式"></a>Lambda表达式</h2><blockquote>
<p>内部类 –&gt; 静态内部类 –&gt; 局部内部类 –&gt; 匿名内部类 –&gt; lambda表达式</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestLambdal</span> &#123;</span><br><span class="line">     </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="comment">//6.用Lambda简化</span></span><br><span class="line">        <span class="type">ILike</span> <span class="variable">iLike</span> <span class="operator">=</span> () -&gt;&#123;</span><br><span class="line">            System.out.println(<span class="string">&quot;I Like Lambda5&quot;</span>);</span><br><span class="line">        &#125;;</span><br><span class="line">        iLike.lambda();</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">interface</span> <span class="title class_">ILike</span>&#123;</span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">lambda</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>





<p><br/>		<br/></p>
<hr>
<h2 id="捕捉-x2F-抛出异常"><a href="#捕捉-x2F-抛出异常" class="headerlink" title="捕捉&#x2F;抛出异常"></a>捕捉&#x2F;抛出异常</h2><ul>
<li><p>处理运行时异常时，采用逻辑去合理规避同时辅助try-catch处理</p>
</li>
<li><p>在多重catch:块后面，可以加一个catch(Exception)来处理可能会被遗漏的异常</p>
</li>
<li><p>对于不确定的代码，也可以加上try-catch,处理潜在的异常</p>
</li>
<li><p>尽量去处理异常，切忌只是简单地调用printStackTrace()去打印输出</p>
</li>
<li><p>具体如何处理异常，要根据不同的业务需求和l异常类型去决定</p>
</li>
<li><p>尽量添加finally语句块去释放占用的资源</p>
</li>
<li><p>try - catch - finally – 捕捉并处理</p>
<p>（最高异常类型 Throwable  异常都可捕捉到）</p>
<p><img src= "" data-lazy-src="/img/loading.gif" data-original="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/image-20230412120716788.png" alt="image-20230412120716788"></p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//捕捉多个异常，异常类型从小到大</span></span><br><span class="line"><span class="keyword">try</span>&#123;<span class="comment">//监控区</span></span><br><span class="line">	<span class="comment">//代码块</span></span><br><span class="line">&#125;<span class="keyword">catch</span>(异常类型 e)&#123;</span><br><span class="line">    <span class="comment">//异常处理代码模块--关闭/回滚</span></span><br><span class="line"></span><br><span class="line">&#125;<span class="keyword">catch</span>(ArithmeticException e)&#123;<span class="comment">//可捕捉多个异常</span></span><br><span class="line">    e.printStackTrace();</span><br><span class="line"></span><br><span class="line">&#125;<span class="keyword">finally</span>&#123;<span class="comment">//处理后续工作（可无）</span></span><br><span class="line">    <span class="comment">//释放资源</span></span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<br/>
</li>
<li><p>throw – throws  抛出异常不处理</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//假设在这个方法中，处理不了这个异常，方法上抛出异常throws --在catch进行捕捉</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">test</span><span class="params">(<span class="type">int</span> a,<span class="type">int</span> b)</span> <span class="keyword">throws</span> ArithmeticException&#123;</span><br><span class="line">    <span class="keyword">if</span>(b==<span class="number">0</span>)&#123;</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">ArithmeticException</span>();<span class="comment">//主动抛出异常，一般在方法中使用--throw</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<br/>

<p>自定义异常</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//定义一个类继承Exception</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">CException</span> <span class="keyword">extends</span> <span class="title class_">Exception</span>&#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="type">int</span> a;</span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">MyException</span><span class="params">(<span class="type">int</span> a)</span>&#123;</span><br><span class="line">        <span class="built_in">this</span>.a=a;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//toString:异常的打印信息</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">toString</span><span class="params">()</span>&#123;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//使用</span></span><br><span class="line"><span class="comment">//方法中</span></span><br><span class="line"><span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">CException</span>(a)</span><br><span class="line"></span><br><span class="line"><span class="keyword">try</span>&#123;</span><br><span class="line">    </span><br><span class="line">&#125;<span class="keyword">catch</span>(CException e)&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
<p><br/>		<br/></p>
<hr>
<h1 id="Java-Doc文档"><a href="#Java-Doc文档" class="headerlink" title="Java Doc文档"></a>Java Doc文档</h1><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">/**</span><br><span class="line"> * @author 作者</span><br><span class="line"> * @version 版本号</span><br><span class="line"> * @since 指明需要最早使用的jdk版本</span><br><span class="line"> * @param 参数名</span><br><span class="line"> * @version 返回值情况</span><br><span class="line"> * @throws 异常抛出情况</span><br><span class="line"> */</span><br><span class="line"></span><br><span class="line">zh_CN</span><br><span class="line">-encoding utf-8 -charset utf-8</span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://example.com">辰</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2021/01/01/Java%E5%9F%BA%E7%A1%80/">http://example.com/2021/01/01/Java%E5%9F%BA%E7%A1%80/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">C·辰</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Java-%E5%9F%BA%E7%A1%80/">Java--基础</a></div><div class="post_share"><div class="social-share" data-image="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/Java.png" data-sites="wechat,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/2021/05/02/Python/" title="Python"><img class="cover" src= "" data-lazy-src="/img/loading.gif" data-original="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/PYTHON.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Python</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2023/07/06/Java%E5%85%AB%E8%82%A1%E6%96%87/" title="Java八股文"><img class="cover" src= "" data-lazy-src="/img/loading.gif" data-original="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/javaall.gif" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-08-15</div><div class="title">Java八股文</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="/img/loading.gif" data-original="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog%2Fimages%2Favatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">辰</div><div class="author-info__description">车遥马慢</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">32</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">28</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/hchenp"><i class="fab fa-github"></i><span>Gitee-HchenP</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/hchenp" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://github.com/Pxlchen?tab=projects" target="_blank" title="CSDN"><i class="fa fa-book-open"></i></a><a class="social-icon" href="https://console.cloud.tencent.com/cos/bucket?bucket=chen-1317386995&amp;region=ap-guangzhou&amp;isPublic=true" target="_blank" title="QQ"><i class="fab fa-qq"></i></a><a class="social-icon" href="mailto:1107383160@qq.com" target="_blank" title="Email"><i class="fas fa-envelope-open-text"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">C2C-Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Java"><span class="toc-number">1.</span> <span class="toc-text">Java</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%8D%E8%BF%90%E7%AE%97"><span class="toc-number">1.1.</span> <span class="toc-text">位运算</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Scanner"><span class="toc-number">1.2.</span> <span class="toc-text">Scanner</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Switch"><span class="toc-number">1.3.</span> <span class="toc-text">Switch</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#While"><span class="toc-number">1.4.</span> <span class="toc-text">While</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#do-while"><span class="toc-number">1.5.</span> <span class="toc-text">do..while</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%93%E6%9D%9F%E5%BE%AA%E7%8E%AF"><span class="toc-number">1.6.</span> <span class="toc-text">结束循环</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0"><span class="toc-number">1.7.</span> <span class="toc-text">可变参数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E7%BB%84-%E2%80%93-Arrays"><span class="toc-number">1.8.</span> <span class="toc-text">数组 – Arrays</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84"><span class="toc-number">1.9.</span> <span class="toc-text">多维数组</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A2%9E%E5%BC%BA%E5%BE%AA%E7%8E%AF"><span class="toc-number">1.10.</span> <span class="toc-text">增强循环</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1"><span class="toc-number">1.11.</span> <span class="toc-text">面向对象</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B0%81%E8%A3%85"><span class="toc-number">1.12.</span> <span class="toc-text">封装</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-number">1.13.</span> <span class="toc-text">修饰符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%A7%E6%89%BF-%E2%80%93-extends"><span class="toc-number">1.14.</span> <span class="toc-text">继承 – extends</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%9A%E6%80%81"><span class="toc-number">1.15.</span> <span class="toc-text">多态</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Static"><span class="toc-number">1.16.</span> <span class="toc-text">Static</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81%E5%9D%97"><span class="toc-number">1.17.</span> <span class="toc-text">代码块</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8A%BD%E8%B1%A1%E7%B1%BB-abstract"><span class="toc-number">1.18.</span> <span class="toc-text">抽象类 - abstract</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A5%E5%8F%A3-%E2%80%93-interface"><span class="toc-number">1.19.</span> <span class="toc-text">接口 – interface</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%B1%BB"><span class="toc-number">1.20.</span> <span class="toc-text">类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">1.20.1.</span> <span class="toc-text">内部类</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">1.20.1.1.</span> <span class="toc-text">静态内部类</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B1%80%E9%83%A8%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">1.20.1.2.</span> <span class="toc-text">局部内部类</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8C%BF%E5%90%8D%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">1.20.1.3.</span> <span class="toc-text">匿名内部类</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="toc-number">1.21.</span> <span class="toc-text">Lambda表达式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8D%95%E6%8D%89-x2F-%E6%8A%9B%E5%87%BA%E5%BC%82%E5%B8%B8"><span class="toc-number">1.22.</span> <span class="toc-text">捕捉&#x2F;抛出异常</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Java-Doc%E6%96%87%E6%A1%A3"><span class="toc-number">2.</span> <span class="toc-text">Java Doc文档</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/07/06/Java%E5%85%AB%E8%82%A1%E6%96%87/" title="Java八股文"><img src= "" data-lazy-src="/img/loading.gif" data-original="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/javaall.gif" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Java八股文"/></a><div class="content"><a class="title" href="/2023/07/06/Java%E5%85%AB%E8%82%A1%E6%96%87/" title="Java八股文">Java八股文</a><time datetime="2023-07-06T14:22:22.000Z" title="发表于 2023-07-06 22:22:22">2023-07-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/07/06/%E5%90%8E%E7%AB%AF%E8%A7%84%E5%88%92/" title="Java后端"><img src= "" data-lazy-src="/img/loading.gif" data-original="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/javahd.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Java后端"/></a><div class="content"><a class="title" href="/2023/07/06/%E5%90%8E%E7%AB%AF%E8%A7%84%E5%88%92/" title="Java后端">Java后端</a><time datetime="2023-07-06T14:22:22.000Z" title="发表于 2023-07-06 22:22:22">2023-07-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/06/02/MybatisPlus/" title="MybatisPlus"><img src= "" data-lazy-src="/img/loading.gif" data-original="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/mybatisplus.svg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MybatisPlus"/></a><div class="content"><a class="title" href="/2023/06/02/MybatisPlus/" title="MybatisPlus">MybatisPlus</a><time datetime="2023-06-02T14:22:22.000Z" title="发表于 2023-06-02 22:22:22">2023-06-02</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/05/05/Linux/" title="Linux"><img src= "" data-lazy-src="/img/loading.gif" data-original="https://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/Linux.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Linux"/></a><div class="content"><a class="title" href="/2023/05/05/Linux/" title="Linux">Linux</a><time datetime="2023-05-05T14:22:22.000Z" title="发表于 2023-05-05 22:22:22">2023-05-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/05/05/Redis/" title="Redis"><img src= "" data-lazy-src="/img/loading.gif" data-original="ttps://chen-1317386995.cos.ap-guangzhou.myqcloud.com/Blog/images/Redis.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Redis"/></a><div class="content"><a class="title" href="/2023/05/05/Redis/" title="Redis">Redis</a><time datetime="2023-05-05T14:22:22.000Z" title="发表于 2023-05-05 22:22:22">2023-05-05</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 辰</div><div class="framework-info"><a target="_blank" rel="noopener" href="https://beian.miit.gov.cn">粤ICP备2023096650号</a><span class="footer-separator">|</span><a target="_blank" rel="noopener" href="http://hchen.cloud">hchen.cloud</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><div class="js-pjax"></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/fireworks.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div>
        <style>
            [bg-lazy] {
                background-image: none !important;
                background-color: #eee !important;
            }
        </style>
        <script>
            window.imageLazyLoadSetting = {
                isSPA: false,
                preloadRatio: 1,
                processImages: null,
            };
        </script><script>window.addEventListener("load",function(){var t=/\.(gif|jpg|jpeg|tiff|png)$/i,r=/^data:image\/[a-z]+;base64,/;Array.prototype.slice.call(document.querySelectorAll("img[data-original]")).forEach(function(a){var e=a.parentNode;"A"===e.tagName&&(e.href.match(t)||e.href.match(r))&&(e.href=a.dataset.original)})});</script><script>!function(r){r.imageLazyLoadSetting.processImages=t;var e=r.imageLazyLoadSetting.isSPA,n=r.imageLazyLoadSetting.preloadRatio||1,c=a();function a(){var t=Array.prototype.slice.call(document.querySelectorAll("img[data-original]")),e=Array.prototype.slice.call(document.querySelectorAll("[bg-lazy]"));return t.concat(e)}function t(){e&&(c=a());for(var t,o=0;o<c.length;o++)0<=(t=(t=c[o]).getBoundingClientRect()).bottom&&0<=t.left&&t.top<=(r.innerHeight*n||document.documentElement.clientHeight*n)&&function(){var t,e,n,a,i=c[o];e=function(){c=c.filter(function(t){return i!==t}),r.imageLazyLoadSetting.onImageLoaded&&r.imageLazyLoadSetting.onImageLoaded(i)},(t=i).hasAttribute("bg-lazy")?(t.removeAttribute("bg-lazy"),e&&e()):(n=new Image,a=t.getAttribute("data-original"),n.onload=function(){t.src=a,t.removeAttribute("data-original"),e&&e()},t.src!==a&&(n.src=a))}()}function i(){clearTimeout(t.tId),t.tId=setTimeout(t,500)}t(),document.addEventListener("scroll",i),r.addEventListener("resize",i),r.addEventListener("orientationchange",i)}(this);</script></body></html>